/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
import { Injectable } from '@angular/core';
import { CommonConsts, SwitchService } from 'app/shared';
import { some } from 'lodash';
import { Observable, Observer } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class CheckDeviceProtectService {
  constructor(private switchService: SwitchService) {}

  getSupportProtectStatus(): Observable<void> {
    return new Observable<void>((observer: Observer<void>) => {
      this.switchService
        .ListSystemSwitchApi({ akDoException: false })
        .subscribe({
          next: (res: any) => {
            CommonConsts.DEVICE_PROTECT_SWITCH = some(
              res?.switches,
              item =>
                item.name === 'NAS_SHARE_AUTO_PROTECT' && item.status === 1
            );
            observer.next();
            observer.complete();
          },
          error: () => {
            observer.next();
            observer.complete();
          }
        });
    });
  }
}
